﻿/***
 * 
 *    Description: 
 *           功能：定义所有UI窗体的父类。
 *           定义四个生命周期
 *           
 *           1：Display 显示状态。
 *           2：Hiding 隐藏状态
 *           3：ReDisplay 再显示状态。
 *           4：Freeze 冻结状态。
 *   
 */
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Design;
using UnityEngine;
using UnityEngine.EventSystems;

public class BaseUIForm : MonoBehaviour, IPointerClickHandler
{
    /*字段*/
    private UIType _CurrentUIType = new UIType();

    /* 属性*/
    //当前UI窗体类型
    public UIType CurrentUIType
    {
        get { return _CurrentUIType; }
        set { _CurrentUIType = value; }
    }


    #region  窗体的四种(生命周期)状态

    /// <summary>
    /// 显示状态
    /// </summary>
    public virtual void Display()
    {
        this.gameObject.SetActive(true);
        //设置模态窗体调用(必须是弹出窗体)
    }

    /// <summary>
    /// 隐藏状态
    /// </summary>
    public virtual void Hiding()
    {
        this.gameObject.SetActive(false);
        //取消模态窗体调用
    }

    /// <summary>
    /// 重新显示状态
    /// </summary>
    public virtual void Redisplay()
    {
        this.gameObject.SetActive(true);
        //设置模态窗体调用(必须是弹出窗体)
    }

    /// <summary>
    /// 冻结状态
    /// </summary>
    public virtual void Freeze()
    {
        this.gameObject.SetActive(true);
    }


    #endregion

    #region 封装子类常用的方法

    /// <summary>
    /// 注册按钮事件
    /// </summary>
    /// <param name="buttonName">按钮节点名称</param>
    /// <param name="delHandle">委托：需要注册的方法</param>

    /// <summary>
    /// 打开UI窗体
    /// </summary>
    /// <param name="uiFormName"></param>
    protected void OpenUIForm(string uiFormName)
    {
        MyUIManager.GetInstance().OpenUIForm(uiFormName);
    }

    /// <summary>
    /// 关闭当前UI窗体
    /// </summary>
    protected void CloseUIForm(string UIFormName)
    {
        //string strUIFromName = string.Empty;            //处理后的UIFrom 名称
        //int intPosition = -1;

        //strUIFromName = GetType().ToString();             //命名空间+类名
        //intPosition = strUIFromName.IndexOf('.');
        //if (intPosition != -1)
        //{
        //    //剪切字符串中“.”之间的部分
        //    strUIFromName = strUIFromName.Substring(intPosition + 1);
        //}

        MyUIManager.GetInstance().CloseUIForm(UIFormName);
    }
    public virtual void OnPointerClick(PointerEventData pointerEventData)
    {
    }

    #endregion

}
